package IO.file;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

public class demo1 {
    @Test
    public void test1() {
        File file1 = new File("hello.txt");
        System.out.println(file1);
        File file = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test\\IO\\In\\hi.txt");
        System.out.println(file);
    }

    @Test
    public void test2() {
        File file = new File("hello.txt");
        File file1 = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test\\IO\\In\\hi.txt");
        System.out.println(file.length());
        System.out.println(file.getAbsoluteFile());
        System.out.println(file.getPath());
        System.out.println(new Date(file.lastModified()));

        System.out.println(file1.getPath());
        System.out.println(file1.getName());
    }

    @Test
    public void test3() {
        File file = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test");

        String[] list = file.list();
        for (String s : list) {
            System.out.println(s);
        }

        System.out.println();

        File[] files = file.listFiles();
        for (File f : files) {
            System.out.println(f);
        }

    }

    @Test
    public void test4() {
        File file1 = new File("hi.txt");
        File file2 = new File("hello.txt");

        boolean renameTo = file1.renameTo(file2);
        System.out.println(renameTo);

    }

    @Test
    public void test5() {
        File file1 = new File("hello.txt");

        System.out.println(file1.isDirectory());
        System.out.println(file1.isFile());
        System.out.println(file1.exists());
        System.out.println(file1.canRead());
        System.out.println(file1.canWrite());
        System.out.println(file1.isHidden());
    }

    @Test
    public void test6() throws IOException {
        File file1 = new File("hi.txt");
        if (!file1.exists()) {
            //文件的创建
            file1.createNewFile();
            System.out.println("创建成功");
        } else {//文件存在
            file1.delete();
            System.out.println("删除成功");
        }
    }

    @Test
    public void test7(){
        //文件目录的创建
        File file1 = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test\\IO\\kk");

        boolean mkdir = file1.mkdir();
        if(mkdir){
            System.out.println("创建成功1");
        }

        File file2 = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test\\IO\\kk\\tt\\ff\\cc");

        boolean mkdir1 = file2.mkdirs();
        if(mkdir1){
            System.out.println("创建成功2");
        }
//        //要想删除成功，io4文件目录下不能有子目录或文件
        File file3 = new File("C:\\Users\\况祥彬\\Desktop\\coding\\code\\Test\\IO\\kk\\tt\\ff");
//        file3 = new File("D:\\io\\io1");
        System.out.println(file3.delete());
    }

}
